package com.ailesson.user.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ailesson.user.model.reply.WxpMenuReply;
import com.ailesson.user.model.req.WxpMenuReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.ailesson.user.service.WxpMenuService;
import com.ailesson.user.model.req.WxpMenuQueryReq;
import com.ailesson.common.reply.PageResult;
import com.ailesson.common.reply.R;



/**
 * 公众号菜单
 *
 * @author mac
 * @email mac@gmail.com
 * @date 2024-10-19 22:39:15
 */
@Tag(name = "公众号菜单模块")
@RestController
@RequestMapping("/admin/user/wxpMenu")
public class WxpMenuController {
    @Autowired
    private WxpMenuService wxpMenuService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @Operation(summary = "列表")
    @Parameter(name = "params", in = ParameterIn.DEFAULT, description = "查询参数")
   // @RequiresPermissions("user:wxpmenu:list")
    public R list(@RequestBody WxpMenuQueryReq params){
        PageResult page = wxpMenuService.queryPage(params);

        return R.success(page);
    }

    /**
     *  获取access_token
     */
    @Operation(summary = "获取token")
    @GetMapping("/getAccessToken")
    public R getAccessToken() {
       return R.success(wxpMenuService.getAccessToken());
    }

    /**
     * 获取所有菜单，按照一级和二级菜单封装
     * @return
     */
    @Operation(summary = "获取所有菜单",description = "按照一级和二级菜单封装")
    @GetMapping("/query/all")
    public R queryAll() {
       return R.success(wxpMenuService.queryAll());
    }

    /**
     * 获取所有一级菜单
     */
    @Operation(summary = "获取所有一级菜单")
    @GetMapping("/query/oneLevel")
    public R queryOneLevel() {
        return R.success(wxpMenuService.queryOneLevel());
    }


    /**
     *  公众号菜单删除
     */

    @Operation(summary = "公众号菜单删除")
    @DeleteMapping("/removeMenu")
    public R removeMenu() {
        wxpMenuService.removeMenu();
        return R.success();
    }

    /**
     * 同步菜单
     * @return
     */
    @Operation(summary = "同步菜单")
    @PostMapping("/sync")
    public R syncMenu(){
        wxpMenuService.syncMenu();
        return R.success();
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @Operation(summary = "获取信息")
    @Parameter(name = "id",in = ParameterIn.PATH, description = "ID")
   // @RequiresPermissions("user:wxpmenu:info")
    public R info(@PathVariable("id") Long id){
		WxpMenuReply wxpMenu = wxpMenuService.info(id);

         return R.success(wxpMenu);
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    @Operation(summary = "添加")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "添加信息")
    //@RequiresPermissions("user:wxpmenu:save")
    public R add(@RequestBody WxpMenuReq wxpMenu){
        return R.success(wxpMenuService.add(wxpMenu));
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @Operation(summary = "更新")
    @Parameter(name = "teacher",in = ParameterIn.QUERY, description = "更新信息")
    //@RequiresPermissions("user:wxpmenu:update")
    public R update(@RequestBody WxpMenuReq wxpMenu){
		wxpMenuService.update(wxpMenu);

        return R.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除")
    @Parameter(name = "ids",in = ParameterIn.QUERY, description = "删除主键ids")
    //@RequiresPermissions("user:wxpmenu:delete")
    public R delete(@RequestBody Long[] ids){
		wxpMenuService.removeByIds(Arrays.asList(ids));

        return R.success();
    }

}
